From 7fb4ddc92e9cb3afb051ad53af28be3c745b483b Mon Sep 17 00:00:00 2001 From: justbur Date: Sun, 12 Jul 2015 11:02:47 -0400 Subject: [PATCH] Cleanup replacement helper functions --- which-key.el | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/which-key.el b/which-key.el index 897af2b890d..8faddbcb674 100644 --- a/which-key.el +++ b/which-key.el @@ -249,16 +249,20 @@ bottom." ;; Helper functions to modify replacement lists. (defun which-key//add-key-based-replacements (alist key repl) + "Internal function to add (KEY . REPL) to ALIST." (when (or (not (stringp key)) (not (stringp repl))) (error "KEY and REPL should be strings")) - (cl-pushnew (cons key repl) alist - :test (lambda (x y) - (let ((cx (car x)) (cy (car y))) - (or (and (stringp cx) (stringp cy) (string-equal cx cy)) - (and (symbolp cx) (symbolp cy) (eq cx cy)))))) + (when (assoc-string key alist) + (message "which-key note: The key %s already exists in %s. This addition will override that replacement.")) + (setq alist (push (cons key repl) alist)) alist) (defun which-key/add-key-based-replacements (key repl &rest more) + "Replace the description of a key sequence KEY (e.g., \"C-c +C-c\") with REPL. Both KEY and REPL should be strings. MORE +allows you to specifcy additional KEY REPL pairs. All +replacements are added to +`which-key-key-based-description-replacement-alist'." ;; TODO: Make interactive (while key (setq which-key-key-based-description-replacement-alist @@ -267,6 +271,9 @@ bottom." (setq key (pop more) repl (pop more)))) (defun which-key/add-major-mode-key-based-replacements (mode key repl &rest more) + "Functions like `which-key/add-key-based-replacements' with the +exception that KEY and REPL (MORE contains addition KEY REPL +pairs) will only apply when the major-mode MODE is active." ;; TODO: Make interactive (when (not (symbolp mode)) (error "MODE should be a symbol corresponding to a value of major-mode")) -- 2.30.2